﻿using UnityEngine;
using UnityEngine.UIElements;

namespace winS.UnityEditor.UIElement
{
    /// <summary>
    /// Icon or Image
    /// </summary>
    public class Icon : VisualElement
    {
        public static readonly Vector2 defaultSize = new Vector2(16f, 16f);

        public Color tintColor { get => imageField.tintColor; set => imageField.tintColor = value; }
        public Texture image { get => imageField.image; set => imageField.image = value; }

        private readonly Image imageField;

        internal Icon()
        {
            style.justifyContent = Justify.Center;

            Add(imageField = new Image());
            imageField.pickingMode = PickingMode.Ignore;
            imageField.style.alignSelf = Align.Center;
            imageField.scaleMode = ScaleMode.ScaleToFit;
            SetSize(defaultSize);
        }

        public void SetSize(float size)
        {
            imageField.style.width = imageField.style.height = size;
        }
        public void SetSize(Vector2 size)
        {
            SetSize(size.x, size.y);
        }
        public void SetSize(float width, float height)
        {
            imageField.style.width = width;
            imageField.style.height = height;
        }
    }
}